package com.example.util.service.impl;

import com.alibaba.fastjson.JSON;
import com.example.util.mq.disruptor.FileReqData;
import com.example.util.mq.disruptor.service.DisruptorMqService;
import com.example.util.service.TaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

@Service
@Slf4j
public class TaskServiceImp implements TaskService {

    @Value("${terminal.manage.url:http://10.10.183.121:16302/ue/v1/capability/5gmsg/sip:106505110000195559@botplatform.rcs.chinamobile.com}")
    private String terminalManageUrl;
    @Value("${terminal.manage.chatbotToken:63f564d57b3df1ab4eb27bb1011b828bc3a6d6846d6cf37914f46c95dc6ba816}")
    private String chatbotToken;

    @Autowired
    private DisruptorMqService disruptorMqService;

    @Override
    public Map<String, Object> writeFileV2(String fileDir, String fileWriterDir, String cardType) {
        Map<String, Object> response = new HashMap<>();
        File file = new File(fileDir);
        if (file.exists()) {
            FileReqData fileReqData = new FileReqData();
            fileReqData.setReadDir(fileDir);
            fileReqData.setWriteDir(fileWriterDir);
            fileReqData.setTerminalManageUrl(terminalManageUrl);
            fileReqData.setToken(chatbotToken);
            fileReqData.setBusiType(3);
            fileReqData.setCardType(cardType);
            disruptorMqService.sendVariableMsg(JSON.toJSONString(fileReqData));
            response.put("code", 0);
            response.put("resaon", "成功");
            return response;

        } else {
            log.info("文件不存在!");
            response.put("code", -100);
            response.put("resaon", "文件不存在");
            return response;
        }
    }
}
